import { fetchList, delObj } from "../api/assess-result";
import editResult from "./edit-result";
import showResult from "./show-result";
export default {
    components: { editResult, showResult },
    mounted() {
				this.getListData();
    },
		provide () {
			return {
				initList: this.getListData
			};
		},
    data() {
        return {
            tableData: [],
						// 请求参数
						params: {
							current: 1,
							size: 20,
							assessName: ""
						},
						// 分页
						pager: {
							total: 0, // 总页数
							current: 1, // 当前页数
							size: 20 // 每页显示多少条
						},
						// 页面loading
						loading: false,
						filterList: [
							{
								label: "考核类别",
								inputType: "dict",
								dictName: "assess_cata",
								name: "assessCatas",
								multiple: true
							},
							{
								label: "考核年份",
								inputType: "dict",
								dictName: "year",
								name: "years",
								multiple: true
							}
						],
        }
    },
    methods: {
				getListData (params = {}) {
					this.loading = true;
					let requestData = { ...this.params, ...params };
					fetchList(requestData)
						.then(res => {
							const { current, size, total, records } = res.data.data;
							this.tableData = records;
							this.params = requestData;
							this.pager = { total, current, size };
						})
						.finally(() => {
							this.loading = false;
						});
				},
        showEditResult(item) {
            this.$refs.editResult.show(item);
        },
        delData(item) {
            if (item) {
                this.confirm("删除确认", "您确定要删除该数据吗？", () => {
                    delObj(item.assessResultId).then(res => {
                        if (res.data.code == 0) {
                            this.$alert("删除成功");
                            this.getListData();
                        }
                    });
                });
            }
        },
        showResult(item) {
            this.$refs.showResult.show(item);
        },
        downloadData() {
            this.publicExport(
                "考核结果记录表",
                "/api/assessresult/download",
                this.searchForm
            );
        },
				// 菜单点击监听
				handleMenuClick (type) {
					switch (type) {
						case "export":
							this.downloadData();
							break;
						default:
							this.$message(type);
							break;
					}
				}
    }
};
